﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PowersourceUIToolkit;
using UCL.Powersource;
using UCL.Powersource.Helpers;

namespace ToolkitTestApp
{
    //ViewModel for powersource
    [Export(typeof(MainViewModel))]
    public class MainViewModel : ViewModelBase
    {

        MainViewModel()
        {
            AvailableTeams = new SelectableConfiguration<LBItem>();
            for (int i = 0; i < 5; i++)
            {
                AvailableTeams.Add(new LBItem() { Name = "Item " + i.ToString(), Index = i });
            }
            AvailableTeams[0].IsSelected = true;
            
        }

        public string _Title = "Test title 1";
        public string Title
        {
            get
            {
                return _Title;
            }
            set
            {
                if (_Title == value) return;
                _Title = value;
                NotifyOfPropertyChange(() => Title);
            }
        }


        #region TitleInternal

        /// <summary>
        /// Field storage for property TitleInternal
        /// </summary>
        private string _TitleInternal = "Default string internal";

        /// <summary>
        /// Property TitleInternal. TODODOC: Insert appropriate summary here
        /// </summary>
        public string TitleInternal
        {
            get { return _TitleInternal; }
            set { if (_TitleInternal == value) return; _TitleInternal = value; TitleInternal_RecalculateDependencies(); }
        }

        private void TitleInternal_RecalculateDependencies()
        {
            //Recalculate all properties here

            //NotifyOfPropertyChange is usually placed as last statement - first change all dependencies and then fire property change
            NotifyOfPropertyChange(() => TitleInternal);
        }

        private void TitleInternal_Recalculate()
        {
            _TitleInternal = default(string);
            //Insert your code here

            TitleInternal_RecalculateDependencies();
        }

        #endregion

        public void ChangeInternalString()
        {
            if (TitleInternal == null) TitleInternal = "#NULL#";
            TitleInternal += " #";
        }


        public class LBItem : ILabel
        {
            public string Label { get { return Name; } }

            public string Name { get; set; }
            public int Index { get; set; }
        }

        public SelectableConfiguration<LBItem> AvailableTeams { get; set; }

        Random rnd = new Random(25);

        public void AddOne()
        {

            var i = rnd.Next(0, 25);
            var li = new LBItem() { Name = "ItR " + i.ToString(), Index = i };
            AvailableTeams.Add(li);
        }

        public void AddOneSelected()
        {
            
        }

        protected override bool OnInitializing()
        {
            return true;
        }

        protected override bool OnActivating()
        {
            return true;
        }

        protected override bool OnDeactivating()
        {
            return true;
        }

        protected override void OnDisposing()
        {
            return ;
        }
    }
}
